package com.cloud.utils;

import com.cloud.canal.mes.MesCanalClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @ClassName ApplicationStartListener
 * @Description 服务启动处理
 * @Author hty
 * @Date 2023/11/24 9:48
 **/
@Component
public class ApplicationStartListener implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private MesCanalClient mesCanalClient;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //解决client.getMessage()  里面死循环，一致不结束 ，下面mvc及page等组件不能继续执行
        new Thread(() -> {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //服务启动开启监听canal
            mesCanalClient.getMessage();
        }).start();
    }
}
